"""WorkBookShop URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, re_path, include
from django.views.static import serve
from django.conf import settings  # 不要使用本地的settings，因为可能少东西
from rest_framework.routers import DefaultRouter

from replace.views import IndexView
# from apps.users import views
from users import views
import xadmin
from rest_framework_jwt.views import obtain_jwt_token

from users.views import SmsCodeViewset, UserViewset
from goods.views import BannerViewset, CategoryViewset, IndexCategoryViewset, GoodsListViewSet, HotSearchsViewset
from trade.views import ShoppingCartViewset, OrderViewset, AlipayView
from user_operation.views import AddressViewset, UserFavViewset, LeavingMessageViewset

router = DefaultRouter()

router.register(r'goods', GoodsListViewSet, basename="goods")

# 配置codes的url
router.register(r'code', SmsCodeViewset, basename="code")

# 配置users的url
router.register(r'users', UserViewset, basename="users")

# 首页banner轮播图url
router.register(r'banners', BannerViewset, basename="banners")

# 配置Category的url
router.register(r'categories', CategoryViewset, basename="categories")

# 首页系列商品展示url
router.register(r'indexgoods', IndexCategoryViewset, basename="indexgoods")

# 热搜词
router.register(r'hotsearchs', HotSearchsViewset, basename="hotsearchs")

# 购物车
router.register(r'shopcarts', ShoppingCartViewset, basename="shopcarts")

# 收货地址
router.register(r'address', AddressViewset, basename="address")

# 订单相关url
router.register(r'orders', OrderViewset, basename="orders")

# 配置用户收藏的url
router.register(r'userfavs', UserFavViewset, basename="userfavs")

# 配置用户留言的url
router.register(r'messages', LeavingMessageViewset, basename="messages")

urlpatterns = [
    # router的path路径
    re_path('^', include(router.urls)),

    # path('admin/', admin.site.urls),
    path('xadmin/', xadmin.site.urls),

    # 打开media路径
    re_path('media/(?P<path>.*)', serve, {'document_root': settings.MEDIA_ROOT}),

    # 测试
    path('test/', views.Test.as_view()),

    # 首页
    path('index/', IndexView.as_view(), name="index"),

    # jwt的token认证
    path('login/', obtain_jwt_token),  # 出乎意料的简单，只需配置这条url就能使用，返回的是token值

    # 支付宝支付相关接口
    path('alipay/return/', AlipayView.as_view()),

]
